#include <bits/stdc++.h>
//Allias//
using namespace std;
typedef long long int lli;
typedef double dbl;
//Macros//
#define pb push_back
// #define pop pop_back
#define pf push_front
#define popf pop_front
#define vec vector <int>
#define vll vector <lli>
#define lb(p,n) lower_bound(p.begin(),p.end(),n)
#define ub(p,n) upper_bound(p.begin(),p.end(),n)
#define prqu priority_queue<lli, vector<lli>, greater<lli>>
#define sqr(r) r * r
#define Nc2(n) (n) * ((n)-1)/2
#define frl(x,n) for(lli i = x; i < n; i++)
#define loop(n) for(lli i = 0; i < n; i++)
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define mp(x,y)make_pair(x,y)
const int N = 1e7;
#define lcm( a ,b) ((lli)a*b/__gcd(a,b))
#define setbit(x,i) (x&(1<<i))
#define totbit(x) ((lli)log2(x)+1)
#define deb(x) cout << #x << "=" << x<<endl
//Constants
constexpr lli M = 1e9+7;
constexpr lli inf = 2e18;
template<typename T> void print_pq(T&q)
{
while(q.size()!=0)
{cout<<q.top()<<" ";
q.pop();}
cout<<endl;
}
bool sortbysecdesc(const pair<int,int> &a,const pair<int,int> &b)
{
return a.second>b.second;
}
void solve()
{
int n,k;
cin>>n>>k;
vector<int> h(n);
vector<int> p(n);
vector<pair<int,int>>h2(n);
vector<int>mini(n);
int dmg=k;
loop(n)
{
cin>>h[i];
}
int mn=INT16_MAX;
loop(n){
cin>>p[i];
}
loop(n)
{h2[i]=mp(h[i],p[i]);}
sort(h2.begin(),h2.end());
mini[n-1]=h2[n-1].second;
for (int i=n-2; i>=0;i--)
{
mini[i]=min(h2[i].second,mini[i+1]);
}
int i=0;
for(;i<n;)
{
if(h2[i].first-(dmg) >0 )
{k=k-mini[i];
dmg=dmg+k;
}
else{i++;}
if(k<=0 ){break;}
}
if(h2[n-1].first<=dmg){cout<<"YES"<<endl;}
else{cout<<"NO"<<endl;}
}
int main()
{
ios_base::sync_with_stdio(true);
cin.tie(0); cout.tie(0);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}
1593C - Save More Mice | 1217. Minimum Cost to Move Chips to The Same Position |
347. Top K Frequent Elements | 1503. Last Moment Before All Ants Fall Out of a Plank |
430. Flatten a Multilevel Doubly Linked List | 1290. Convert Binary Number in a Linked List to Integer |
1525. Number of Good Ways to Split a String | 72. Edit Distance |
563. Binary Tree Tilt | 1306. Jump Game III |
236. Lowest Common Ancestor of a Binary Tree | 790. Domino and Tromino Tiling |
878. Nth Magical Number | 2099. Find Subsequence of Length K With the Largest Sum |
1608A - Find Array | 416. Partition Equal Subset Sum |
1446. Consecutive Characters | 1618A - Polycarp and Sums of Subsequences |
1618B - Missing Bigram | 938. Range Sum of BST |
147. Insertion Sort List | 310. Minimum Height Trees |
2110. Number of Smooth Descent Periods of a Stock | 2109. Adding Spaces to a String |
2108. Find First Palindromic String in the Array | 394. Decode String |
902. Numbers At Most N Given Digit Set | 221. Maximal Square |
1200. Minimum Absolute Difference | 1619B - Squares and Cubes |